/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;


import DBH.DBHelper;
import com.sun.org.glassfish.external.statistics.Statistic;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JOptionPane;

/**
 *
 * @author Cun_con_yeu_em
 */
public class B_khachhang {
    private DBHelper obj = new DBHelper();
    private Vector v;
    private String idkh;
    private String ten;
    private String sodienthoai;
    private String diachi;

        public B_khachhang() {};
        public B_khachhang(String idkh,String ten,String sodienthoai,String diachi) {
        this.idkh = idkh;
        this.ten = ten;
        this.sodienthoai = sodienthoai;
        this.diachi =  diachi;
        
        }
        
        // Thêm một khách hàng
        public int insertKhachhang(B_khachhang k) throws SQLException {
        
        int i = 0;
        try 
        {
         Vector v = new Vector();
         v.add(k.getIdkh());
         v.add(k.getTen());
         v.add(k.getSodienthoai());
         v.add(k.getDiachi());
        i= DBHelper.executeUpdate("sp_insertKhachhang", v) ;
        }
        catch (SQLException e)
        {
        }
        return i;
        }
        
        // Sửa một khách hàng
        public int updateKhachhang(B_khachhang k) throws SQLException {
        int i = 0;
        try {
            Vector paramList = new Vector();
            paramList.add(k.getIdkh());
            paramList.add(k.getTen());
            paramList.add(k.getSodienthoai());
            paramList.add(k.getDiachi());
            i = DBHelper.executeUpdate("sp_updateKhachhang", paramList);
        } catch (SQLException sqlex) {
        }
        return i;
    }
        
        // Xóa một khách hàng
        public int deleteKhachhang(String idkh) throws SQLException {
        int i = 0;
        try {
            Vector paramList = new Vector();
            paramList.add(idkh);
            i = DBHelper.executeUpdate("sp_deleteKhachhang", paramList);
        } catch (SQLException sqlex) {
        }
        return i;
    }

        public Vector getAllkhachhang() throws SQLException {
        
        Vector v = new Vector();
        try
        {
        ResultSet rs = obj.executeQuery("sp_getAllkhachhang");
        while(rs.next())
        {
            B_khachhang k = new B_khachhang();
            k.setIdkh(rs.getString(1));
            k.setTen(rs.getString(2));
            k.setSodienthoai(rs.getString(3));
            k.setDiachi(rs.getString(4));
            v.add(k);
        }
        }
        catch (SQLException sqle)  
        {
        }
        return v;
        }
                
        
        public Vector search(String name) throws SQLException {

        Vector v = new Vector();
        Vector paramList = new Vector();
        paramList.add(name);
        try {
            ResultSet rs = DBHelper.executeQuery("sp_searchKhachhang", paramList);
            while (rs.next()) {
                B_khachhang s = new B_khachhang();
                s.setIdkh(rs.getString(1));
                s.setTen(rs.getString(2));
                s.setSodienthoai(rs.getString(3));
                s.setDiachi(rs.getString(4));
               
                v.add(s);

            }
        } catch (SQLException sqle) {
        }
        return v;
    }
    /**
     * @return the idkh
     */
    public String getIdkh() {
        return idkh;
    }

    /**
     * @param idkh the idkh to set
     */
    public void setIdkh(String idkh) {
        this.idkh = idkh;
    }

    /**
     * @return the ten
     */
    public String getTen() {
        return ten;
    }

    /**
     * @param ten the ten to set
     */
    public void setTen(String ten) {
        this.ten = ten;
    }

    /**
     * @return the sodienthoai
     */
    public String getSodienthoai() {
        return sodienthoai;
    }

    /**
     * @param sodienthoai the sodienthoai to set
     */
    public void setSodienthoai(String sodienthoai) {
        this.sodienthoai = sodienthoai;
    }

    /**
     * @return the diachi
     */
    public String getDiachi() {
        return diachi;
    }

    /**
     * @param diachi the diachi to set
     */
    public void setDiachi(String diachi) {
        this.diachi = diachi;
    }
    
}
